home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / biblio / bibtex / contrib / big / bibtex.web2c-changes < prev    next >
Text File  |  1988-11-08  |  17KB  |  567 lines

  1. % Change file for BibTeX for Berkeley UNIX, by H. Trickey
  2. % History:
  3. % 5/28/84    Initial implementation, version 0.41 of BibTeX
  4. % 7/1/84    Version 0.41a of BibTeX.
  5. % 12/17/84    Version 0.97c of BibTeX.
  6. % 2/12/85    Version 0.98c of BibTeX.
  7. % 2/25/85    Newer Version 0.98c of BibTeX
  8. % 3/25/85    Version 0.98f of BibTeX
  9. % 5/23/85    Version 0.98i of BibTeX
  10. % 2/11/88       Version 0.99b of BibTeX
  11. % 4/ 4/88    Version 0.99c; converted for use with web2c (ETM).
  12.  
  13. @x banner
  14. @d banner=='This is BibTeX, Version 0.99c' {printed when the program starts}
  15. @y
  16. @d banner=='This is BibTeX, HUGE Version 0.99c' {printed when the program starts}
  17. @z
  18.  
  19. @x terminal
  20. @d term_out == tty
  21. @d term_in == tty
  22. @y
  23. @d term_out == stdout
  24. @d term_in == stdin
  25. @z
  26.  
  27. @x debug..gubed, stat..tats, trace..ecart
  28. @d debug == @{        { remove the `|@{|' when debugging }
  29. @d gubed == @t@>@}    { remove the `|@}|' when debugging }
  30. @f debug == begin
  31. @f gubed == end
  32. @#
  33. @d stat == @{        { remove the `|@{|' when keeping statistics }
  34. @d tats == @t@>@}    { remove the `|@}|' when keeping statistics }
  35. @f stat == begin
  36. @f tats == end
  37. @#
  38. @d trace == @{        { remove the `|@{|' when in |trace| mode }
  39. @d ecart == @t@>@}    { remove the `|@}|' when in |trace| mode }
  40. @f trace == begin
  41. @f ecart == end
  42. @y
  43. @d debug == ifdef('DEBUG')
  44. @d gubed == endif('DEBUG')
  45. @f debug == begin
  46. @f gubed == end
  47. @#
  48. @d stat == ifdef('STAT')
  49. @d tats == endif('STAT')
  50. @f stat==begin
  51. @f tats==end
  52. @#
  53. @d trace == ifdef@&('TRACE')
  54. @d ecart == endif@&('TRACE')
  55. @f trace == begin
  56. @f ecart == end
  57. @z
  58.  
  59. @x
  60. @d incr(#) == #:=#+1    {increase a variable by unity}
  61. @d decr(#) == #:=#-1    {decrease a variable by unity}
  62. @y
  63. {These are defined as C macros}
  64. @z
  65.  
  66. @x compiler directives
  67. @{@&$C-,A+,D-@}     {no range check, catch arithmetic overflow, no debug overhead}
  68. @!debug @{@&$C+,D+@}@+ gubed        {but turn everything on when debugging}
  69. @y
  70. {Don't need 'em for C}
  71. @z
  72.  
  73. @x
  74.     goto exit_program;
  75. @y
  76.     uexit(0);
  77. @z
  78.  
  79. @x increase buf_size
  80. @!buf_size=1000; {maximum number of characters in an input line (or string)}
  81. @y
  82. @!buf_size=3000; {maximum number of characters in an input line (or string)}
  83. @z
  84.  
  85. @x increase pool_size
  86. @!pool_size=65000; {maximum number of characters in strings}
  87. @!max_strings=4000; {maximum number of strings, including pre-defined;
  88.                             must be |<=hash_size|}
  89. @!max_cites=750; {maximum number of distinct cite keys; must be
  90.                             |<=max_strings|}
  91. @y
  92. @!pool_size=251635; {maximum number of characters in strings}
  93. @!max_strings=15360; {maximum number of strings, including pre-defined;
  94.                             must be |<=hash_size|}
  95. @!max_cites=2880; {maximum number of distinct cite keys; must be
  96.                             |<=max_strings|}
  97. @z
  98.  
  99. @x
  100. @!max_fields=17250; {maximum number of fields (entries $\times$ fields,
  101.                     about |23*max_cites| for consistency)}
  102. @y
  103. @!max_fields=66240; {maximum number of fields (entries $\times$ fields,
  104.                     about |23*max_cites| for consistency)}
  105. @z
  106.  
  107. @x increase file_name_size
  108. @d hash_size=5000    {must be |>= max_strings| and |>= hash_prime|}
  109. @d hash_prime=4253    {a prime number about 85\% of |hash_size| and |>= 128|
  110.                         and |< @t$2^{14}-2^6$@>|}
  111. @d file_name_size=40    {file names shouldn't be longer than this}
  112. @y
  113. @d hash_size=19200    {must be |>= max_strings| and |>= hash_prime|}
  114. @d hash_prime=16319    {a prime number about 85\% of |hash_size| and |>= 128|
  115.                         and |< @t$2^{14}-2^6$@>|}
  116. @d file_name_size=1024    {file names shouldn't be longer than this}
  117. @z
  118.  
  119. @x declare real_name_of_file
  120. Most of what we need to do with respect to input and output can be handled
  121. by the I/O facilities that are standard in \PASCAL, i.e., the routines
  122. called |get|, |put|, |eof|, and so on. But
  123. standard \PASCAL\ does not allow file variables to be associated with file
  124. names that are determined at run time, so it cannot be used to implement
  125. \BibTeX; some sort of extension to \PASCAL's ordinary |reset| and |rewrite|
  126. is crucial for our purposes. We shall assume that |name_of_file| is a variable
  127. of an appropriate type such that the \PASCAL\ run-time system being used to
  128. implement \BibTeX\ can open a file whose external name is specified by
  129. |name_of_file|. \BibTeX\ does no case conversion for file names.
  130.  
  131. @<Globals in the outer block@>=
  132. @!name_of_file:packed array[1..file_name_size] of char;
  133.              {on some systems this is a \&{record} variable}
  134. @y
  135. Most of what we need to do with respect to input and output can be handled
  136. by the I/O facilities that are standard in \PASCAL, i.e., the routines
  137. called |get|, |put|, |eof|, and so on. But
  138. standard \PASCAL\ does not allow file variables to be associated with file
  139. names that are determined at run time, so it cannot be used to implement
  140. \BibTeX; some sort of extension to \PASCAL's ordinary |reset| and |rewrite|
  141. is crucial for our purposes. We shall assume that |name_of_file| is a variable
  142. of an appropriate type such that the \PASCAL\ run-time system being used to
  143. implement \BibTeX\ can open a file whose external name is specified by
  144. |name_of_file|. \BibTeX\ does no case conversion for file names.
  145.  
  146. The C version of BibTeX uses search paths to look for files to open.
  147. We use |real_name_of_file| to hold the |name_of_file| with a directory name
  148. from the path in front of it.
  149.  
  150. @<Globals in the outer block@>=
  151. @!name_of_file,@!real_name_of_file:packed array[1..file_name_size] of char;
  152. @z
  153.  
  154. @x opening files
  155. The \ph\ compiler with which the present version of \TeX\ was prepared has
  156. extended the rules of \PASCAL\ in a very convenient way. To open file~|f|,
  157. we can write
  158. $$\vbox{\halign{#\hfil\qquad&#\hfil\cr
  159. |reset(f,@t\\{name}@>,'/O')|&for input;\cr
  160. |rewrite(f,@t\\{name}@>,'/O')|&for output.\cr}}$$
  161. The `\\{name}' parameter, which is of type `\ignorespaces|packed
  162. array[@t\<\\{any}>@>] of text_char|', stands for the name of
  163. the external file that is being opened for input or output.
  164. Blank spaces that might appear in \\{name} are ignored.
  165.  
  166. The `\.{/O}' parameter tells the operating system not to issue its own
  167. error messages if something goes wrong. If a file of the specified name
  168. cannot be found, or if such a file cannot be opened for some other reason
  169. (e.g., someone may already be trying to write the same file), we will have
  170. |@!erstat(f)<>0| after an unsuccessful |reset| or |rewrite|.  This allows
  171. \TeX\ to undertake appropriate corrective action.
  172.  
  173. \TeX's file-opening procedures return |false| if no file identified by
  174. |name_of_file| could be opened.
  175.  
  176. @d reset_OK(#)==erstat(#)=0
  177. @d rewrite_OK(#)==erstat(#)=0
  178.  
  179. @<Procedures and functions for file-system interacting@>=
  180. function erstat(var f:file):integer; extern;    {in the runtime library}
  181. @#@t\2@>
  182. function a_open_in(var f:alpha_file):boolean;    {open a text file for input}
  183. begin reset(f,name_of_file,'/O'); a_open_in:=reset_OK(f);
  184. end;
  185. @#
  186. function a_open_out(var f:alpha_file):boolean;    {open a text file for output}
  187. begin rewrite(f,name_of_file,'/O'); a_open_out:=rewrite_OK(f);
  188. end;
  189. @y
  190. @ The \ph\ compiler with which the present version of \TeX\ was prepared has
  191. extended the rules of \PASCAL\ in a very convenient way for file opening.
  192. Berkeley {\mc UNIX} \PASCAL\ isn't nearly as nice as \ph.
  193. Normally, it bombs out if a file open fails.
  194. An external C procedure, |test_access| is used to check whether or not the
  195. open will work.  It is declared in the ``ext.h'' include file, and it returns
  196. |true| or |false|. The |name_of_file| global holds the file name whose access
  197. is to be tested.
  198. The first parameter for |test_access| is the access mode,
  199. one of |read_access_mode| or |write_access_mode|.
  200.  
  201. We also implement path searching in |test_access|:  its second parameter is
  202. one of the ``file path'' constants defined below.  If |name_of_file|
  203. doesn't start with |'/'| then |test_access| tries prepending pathnames
  204. from the appropriate path list until success or the end of path list
  205. is reached.
  206. On return, |real_name_of_file| contains the original name with the path
  207. that succeeded (if any) prepended.  It is the name used in the various
  208. open procedures.
  209.  
  210. Path searching is not done for output files.
  211.  
  212. @d read_access_mode=4  {``read'' mode for |test_access|}
  213. @d write_access_mode=2 {``write'' mode for |test_access|}
  214.  
  215. @d no_file_path=0    {no path searching should be done}
  216. @d input_file_path=1 {path specifier for input files}
  217.  
  218. @<Procedures and functions for file-system interacting@>=
  219. function a_open_in(var f:palpha_file):boolean;
  220.   {open a text file for input}
  221. var @!ok:boolean;
  222. begin
  223. if test_access(read_access_mode,input_file_path) then
  224.     begin reset(f,real_name_of_file); ok:=true@+end
  225. else
  226.     ok:=false;
  227. a_open_in:=ok;
  228. end;
  229. @#
  230. function a_open_out(var f:palpha_file):boolean;
  231.   {open a text file for output}
  232. var @!ok:boolean;
  233. begin
  234. if test_access(write_access_mode,no_file_path) then
  235.     begin rewrite(f,real_name_of_file); ok:=true @+end
  236. else ok:=false;
  237. a_open_out:=ok;
  238. end;
  239. @z
  240.  
  241. @x
  242. @<Procedures and functions for file-system interacting@>=
  243. procedure a_close(var f:alpha_file);        {close a text file}
  244. begin close(f);
  245. end;
  246. @y
  247. {aclose will be defined as a C macro}
  248. @z
  249.  
  250. %%%%% overflow and confusion go here 
  251. @x faster input_ln
  252. Standard \PASCAL\ says that a file should have |eoln| immediately
  253. before |eof|, but \BibTeX\ needs only a weaker restriction: If |eof|
  254. occurs in the middle of a line, the system function |eoln| should return
  255. a |true| result (even though |f^| will be undefined).
  256.  
  257. @<Procedures and functions for all file I/O, error messages, and such@>=
  258. function input_ln(var f:alpha_file) : boolean;
  259.                 {inputs the next line or returns |false|}
  260. label loop_exit;
  261. begin
  262. last:=0;
  263. if (eof(f)) then input_ln:=false
  264. else
  265.   begin
  266.   while (not eoln(f)) do
  267.     begin
  268.     if (last >= buf_size) then
  269.     buffer_overflow;
  270.     buffer[last]:=xord[f^];
  271.     get(f); incr(last);
  272.     end;
  273.   get(f);
  274.   while (last > 0) do        {remove trailing |white_space|}
  275.     if (lex_class[buffer[last-1]] = white_space) then
  276.       decr(last)
  277.      else
  278.       goto loop_exit;
  279. loop_exit:
  280.   input_ln:=true;
  281.   end;
  282. end;
  283. @y
  284. With Berkeley {\mc UNIX} we call an external C procedure, |line_read|.
  285. That routine fills |buffer| from |0| onwards with the |xord|'ed values
  286. of the next line, setting |last| appropriately.  It will stop if
  287. |last=buf_size|, and the following will cause an ``overflow'' abort.
  288.  
  289. @<Procedures and functions for all file I/O, error messages, and such@>=
  290. function input_ln(var f:alpha_file) : boolean;
  291.   {inputs the next line or returns |false|}
  292. label loop_exit;
  293. begin
  294. last:=0;
  295. if eof(f) then input_ln:=false
  296. else
  297.   begin
  298.   line_read(f,buf_size);
  299.   if last>=buf_size then
  300.     overflow('buffer size ',buf_size);
  301.   while (last > 0) do        {remove trailing |white_space|}
  302.     if lex_class[buffer[last-1]] = white_space then
  303.       decr(last)
  304.      else
  305.       goto loop_exit;
  306. loop_exit:
  307.   input_ln:=true;
  308.   end;
  309. end;
  310. @z
  311.  
  312. @x
  313. if (length(file_name) > file_name_size) then
  314.     begin
  315.     print ('File=');
  316.     print_pool_str (file_name);
  317.     print_ln (',');
  318.     file_nm_size_overflow;
  319.     end;
  320. name_ptr := 1;
  321. @y
  322. if (length(file_name) > file_name_size) then
  323.     begin
  324.     print ('File=');
  325.     print_pool_str (file_name);
  326.     print_ln (',');
  327.     file_nm_size_overflow;
  328.     end;
  329. name_ptr := 0;
  330. @z
  331.  
  332. @x
  333. name_ptr := name_length + 1;
  334. p_ptr := str_start[ext];
  335. while (p_ptr < str_start[ext+1]) do
  336.     begin
  337.     name_of_file[name_ptr] := chr (str_pool[p_ptr]);
  338.     incr(name_ptr); incr(p_ptr);
  339.     end;
  340. name_length := name_length + length(ext);
  341. name_ptr := name_length+1;
  342. while (name_ptr <= file_name_size) do    {pad with blanks}
  343.     begin
  344.     name_of_file[name_ptr] := ' ';
  345.     incr(name_ptr);
  346.     end;
  347. @y
  348. name_ptr := name_length;
  349. p_ptr := str_start[ext];
  350. while (p_ptr < str_start[ext+1]) do
  351.     begin
  352.     name_of_file[name_ptr] := chr (str_pool[p_ptr]);
  353.     incr(name_ptr); incr(p_ptr);
  354.     end;
  355. name_length := name_length + length(ext);
  356. name_of_file[name_length] := ' ';
  357. @z
  358.  
  359. @x
  360.     print_pool_str (area); print (name_of_file,',');
  361.     file_nm_size_overflow;
  362.     end;
  363. name_ptr := name_length;
  364. while (name_ptr > 0) do        {shift up name}
  365.     begin
  366.     name_of_file[name_ptr+length(area)] := name_of_file[name_ptr];
  367.     decr(name_ptr);
  368.     end;
  369. name_ptr := 1;
  370. p_ptr := str_start[area];
  371. while (p_ptr < str_start[area+1]) do
  372. @y
  373.     print_pool_str (area); print_str (name_of_file,',');
  374.     file_nm_size_overflow;
  375.     end;
  376. name_ptr := name_length;
  377. while (name_ptr > 0) do        {shift up name}
  378.     begin
  379.     name_of_file[name_ptr+length(area)] := name_of_file[name_ptr];
  380.     decr(name_ptr);
  381.     end;
  382. name_ptr := 0;
  383. p_ptr := str_start[area];
  384. while (p_ptr < str_start[area+1]) do
  385. @z
  386.  
  387. @x
  388. for i:=1 to len do
  389.     buffer[i] := xord[pds[i]];
  390. @y
  391. for i:=1 to len do
  392.     buffer[i] := xord[pds[i-1]];
  393. @z
  394.  
  395. @x
  396. procedure sam_too_long_file_name_print;
  397. begin
  398. write (term_out,'File name `');
  399. name_ptr := 1;
  400. while (name_ptr <= aux_name_length) do
  401.     begin
  402.     write (term_out,name_of_file[name_ptr]);
  403. @y
  404. procedure sam_too_long_file_name_print;
  405. begin
  406. write (term_out,'File name `');
  407. name_ptr := 0;
  408. while (name_ptr < aux_name_length) do
  409.     begin
  410.     write (term_out,name_of_file[name_ptr]);
  411. @z
  412.  
  413. @x
  414. procedure sam_wrong_file_name_print;
  415. begin
  416. write (term_out,'I couldn''t open file name `');
  417. name_ptr := 1;
  418. while (name_ptr <= name_length) do
  419.     begin
  420.     write (term_out,name_of_file[name_ptr]);
  421.     incr(name_ptr);
  422.     end;
  423. write_ln (term_out,'''');
  424. end;
  425. @y
  426. procedure sam_wrong_file_name_print;
  427. begin
  428. write (term_out,'I couldn''t open file name `');
  429. name_ptr := 0;
  430. while (name_ptr < name_length) do
  431.     begin
  432.     write (term_out,name_of_file[name_ptr]);
  433.     incr(name_ptr);
  434.     end;
  435. write_ln (term_out,'''');
  436. end;
  437. @z
  438.  
  439. @x reading the command line
  440. This procedure consists of a loop that reads and processes a (nonnull)
  441. \.{.aux} file name.  It's this module and the next two that must be
  442. changed on those systems using command-line arguments.  Note: The
  443. |term_out| and |term_in| files are system dependent.
  444.  
  445. @<Procedures and functions for the reading and processing of input files@>=
  446. procedure get_the_top_level_aux_file_name;
  447. label aux_found,@!aux_not_found;
  448. var @<Variables for possible command-line processing@>@/
  449. begin
  450. check_cmnd_line := false;            {many systems will change this}
  451. loop
  452.     begin
  453.     if (check_cmnd_line) then
  454.     @<Process a possible command line@>
  455.       else
  456.     begin
  457.     write (term_out,'Please type input file name (no extension)--');
  458.     if (eoln(term_in)) then            {so the first |read| works}
  459.         read_ln (term_in);
  460.     aux_name_length := 0;
  461.     while (not eoln(term_in)) do
  462.         begin
  463.         if (aux_name_length = file_name_size) then
  464.         begin
  465.         while (not eoln(term_in)) do    {discard the rest of the line}
  466.             get(term_in);
  467.         sam_you_made_the_file_name_too_long;
  468.         end;
  469.         incr(aux_name_length);
  470.         name_of_file[aux_name_length] := term_in^;
  471.         get(term_in);
  472.         end;
  473.     end;
  474.     @<Handle this \.{.aux} name@>;
  475. aux_not_found:
  476.     check_cmnd_line := false;
  477.     end;
  478. aux_found:            {now we're ready to read the \.{.aux} file}
  479. end;
  480. @y
  481. @<Procedures and functions for the reading and processing of input files@>=
  482. procedure get_the_top_level_aux_file_name;
  483. label aux_found,@!aux_not_found;
  484. begin
  485. loop
  486.     begin
  487.     if (gargc > 1) then
  488.     @<Process a possible command line@>
  489.       else
  490.     begin
  491.     write (term_out,'Please type input file name (no extension)--');
  492.     aux_name_length := 0;
  493.     while (not eoln(term_in)) do
  494.         begin
  495.         if (aux_name_length = file_name_size) then
  496.         begin
  497.         readln(term_in);
  498.         sam_you_made_the_file_name_too_long;
  499.         end;
  500.         name_of_file[aux_name_length] := getc(term_in);
  501.         incr(aux_name_length);
  502.         end;
  503.     end;
  504.     @<Handle this \.{.aux} name@>;
  505. aux_not_found:
  506.     gargc := 0;
  507.     end;
  508. aux_found:            {now we're ready to read the \.{.aux} file}
  509. end;
  510. @z
  511.  
  512. @x
  513. @<Variables for possible command-line processing@>=
  514. @!check_cmnd_line : boolean;    {|true| if we're to check the command line}
  515. @y
  516. @z
  517.  
  518. @x
  519. @<Process a possible command line@>=
  520. begin
  521. do_nothing;        {the ``default system'' doesn't use the command line}
  522. end
  523. @y
  524. @<Process a possible command line@>=
  525. aux_name_length := get_cmd_line(name_of_file, file_name_size)
  526. @z
  527.  
  528. @x
  529. while (name_ptr <= name_length) do
  530.     begin
  531.     buffer[name_ptr] := xord[name_of_file[name_ptr]];
  532.     incr(name_ptr);
  533.     end;
  534. @y
  535. while (name_ptr <= name_length) do
  536.     begin
  537.     buffer[name_ptr] := xord[name_of_file[name_ptr-1]];
  538.     incr(name_ptr);
  539.     end;
  540. @z
  541.  
  542. @x
  543. name_ptr := name_length+1;
  544. @y
  545. name_ptr := name_length;
  546. @z
  547.  
  548. @x
  549. buf_ptr2 := last;    {to get the first input line}
  550. loop
  551.     begin
  552.     if (not eat_bst_white_space) then    {the end of the \.{.bst} file}
  553.     goto bst_done;
  554.     get_bst_command_and_process;
  555.     end;
  556. bst_done: a_close (bst_file);
  557. @y
  558. buf_ptr2 := last;    {to get the first input line}
  559. hack1;
  560.     begin
  561.     if (not eat_bst_white_space) then    {the end of the \.{.bst} file}
  562.     hack2;
  563.     get_bst_command_and_process;
  564.     end;
  565. bst_done: a_close (bst_file);
  566. @z
  567.